package org.testis.services;

import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import java.lang.reflect.Method;


/**
 * A factory class to create a module service factory object dynamically 
 * according to module type
 * @author nurhat
 */
public class AtofModuleServiceFactory
{

    public AtofModuleService getInstance(String moduleType)
    {
        try {

            Class<?> cls =
                Class.forName("org.testis." + moduleType.toLowerCase() +
                              ".services." + moduleType +
                              "ProviderServiceFactory");
            Method mainMethod =
                cls.getMethod("getService",
                              new Class[]{});
            AtofModuleService service =
                (AtofModuleService) mainMethod.invoke(null,
                                                      new Object[]{});
            return service;
        } catch (Exception ex) {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "(" + ex.getClass().getSimpleName() +
                                        ")Given module type" + moduleType +
                                        " is not supported righ now at AtofModuleServiceFactory");

        }
    }
}
